﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class cantaizhuangtai : Form
    {
        public cantaizhuangtai()
        {
            InitializeComponent();
        }
        public  int czno;
        string constr = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";

        private void cantaizhuangtai_Load(object sender, EventArgs e)
        {
            string sql = @"SELECT  [Table].czID, Tablecondition.czName
FROM      [Table] INNER JOIN
                   Tablecondition ON [Table].cz = Tablecondition.cz where czID='"+czno+"'";
            SqlConnection sqlcon = new SqlConnection(constr);
            sqlcon.Open();
            SqlCommand sqlcom = new SqlCommand(sql,sqlcon);
            SqlDataReader reader = sqlcom.ExecuteReader();
            if (reader.Read())
            {
                label3.Text =Convert.ToString(reader["czID"]);
                label4.Text = Convert.ToString(reader["czName"]);
            }
            sqlcon.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = "update [Table]  set cz='2'   where czID='"+czno+"'";
            SqlConnection sqlcon = new SqlConnection(constr);
            sqlcon.Open();
            SqlCommand sqlcom = new SqlCommand(sql,sqlcon);
            if (sqlcom.ExecuteNonQuery()>0)
            {
                MessageBox.Show("变更成功");
            }
            else
            {
                MessageBox.Show("变更失败");
            }
            sqlcon.Close();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string sql = "update [Table]  set cz='3'   where czID='" + czno + "'";
            SqlConnection sqlcon = new SqlConnection(constr);
            sqlcon.Open();
            SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
            if (sqlcom.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("变更成功");
            }
            else
            {
                MessageBox.Show("变更失败");
            }
            sqlcon.Close();
            this.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string sql = "update [Table]  set cz='4'   where czID='" + czno + "'";
            SqlConnection sqlcon = new SqlConnection(constr);
            sqlcon.Open();
            SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
            if (sqlcom.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("变更成功");
            }
            else
            {
                MessageBox.Show("变更失败");
            }
            sqlcon.Close();
            this.Close();
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string sql = "update [Table]  set cz='5'   where czID='" + czno + "'";
            SqlConnection sqlcon = new SqlConnection(constr);
            sqlcon.Open();
            SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
            if (sqlcom.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("变更成功");
            }
            else
            {
                MessageBox.Show("变更失败");
            }
            sqlcon.Close();
            this.Close();
        }

    }
}
